package com.ht.medicaltreatment

import android.content.Context
import com.blankj.utilcode.util.CrashUtils
import com.blankj.utilcode.util.LogUtils
import com.gym.baselib.BaseApplication
import com.hjq.http.EasyConfig
import com.pgyer.pgyersdk.PgyerSDKManager
import com.xgst.smallscreen.http.RequestHandler
import com.xgst.smallscreen.http.RequestServer
import okhttp3.OkHttpClient

const val API_KEY = "a6a16c44edf916854a5e92e68d872395"
const val FRONT_JS_TOKEN = "9f2fee46441ddf0141cad4a3d0a3417f"

class App : BaseApplication() {

    override fun init() {
        LogUtils.getConfig()
            .setLog2FileSwitch(true)
            .globalTag = "ttt"

        CrashUtils.init()

        initHttp()
    }

    override fun attachBaseContext(base: Context?) {
        super.attachBaseContext(base)
        initPagerSdk()
    }

    private fun initPagerSdk(){
        PgyerSDKManager
            .Init()
            .setContext(this)
            .setApiKey(API_KEY)
            .setFrontJSToken(FRONT_JS_TOKEN)
            .start()
    }

    private fun initHttp() {
        val okHttpClient = OkHttpClient.Builder()
            //.cookieJar(RetrofitUtils.getCookie())
            .build()
        EasyConfig.with(okHttpClient)
            .setServer(RequestServer())
            .setHandler(RequestHandler())
            .setRetryCount(3)
            .into()
        if (!BuildConfig.DEBUG) {
            //EasyConfig.getInstance().logStrategy = LogStrategy()
        }
    }
}